
package cn.edu.scau.cmi.hombio.service;

import cn.edu.scau.cmi.hombio.domain.Function;
import cn.edu.scau.cmi.hombio.domain.RoleAuthority;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./resources/pigRs-security-context.xml",
		"file:./resources/pigRs-service-context.xml",
		"file:./resources/pigRs-dao-context.xml",
		"file:./resources/pigRs-web-context.xml" })
@Transactional
public class FunctionServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected FunctionService service;

	/**
	 * Instantiates a new FunctionServiceTest.
	 *
	 */
	public FunctionServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	* Load an existing Function entity
	* 
	 */
	@Test
	public void loadFunctions() {
		Set<Function> response = null;
		response = service.loadFunctions();
		// TODO: JUnit - Add assertions to test outputs of operation: loadFunctions
	}

	/**
	 * Operation Unit Test
	* Save an existing RoleAuthority entity
	* 
	 */
	@Test
	public void saveFunctionRoleAuthorities() {
		// TODO: JUnit - Populate test inputs for operation: saveFunctionRoleAuthorities 
		Integer id = 0;
		RoleAuthority related_roleauthorities = new cn.edu.scau.cmi.hombio.domain.RoleAuthority();
		Function response = null;
		response = service.saveFunctionRoleAuthorities(id, related_roleauthorities);
		// TODO: JUnit - Add assertions to test outputs of operation: saveFunctionRoleAuthorities
	}

	/**
	 * Operation Unit Test
	* Return all Function entity
	* 
	 */
	@Test
	public void findAllFunctions() {
		// TODO: JUnit - Populate test inputs for operation: findAllFunctions 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<Function> response = null;
		response = service.findAllFunctions(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllFunctions
	}

	/**
	 * Operation Unit Test
	* Return a count of all Function entity
	* 
	 */
	@Test
	public void countFunctions() {
		Integer response = null;
		response = service.countFunctions();
		// TODO: JUnit - Add assertions to test outputs of operation: countFunctions
	}

	/**
	 * Operation Unit Test
	* Save an existing Function entity
	* 
	 */
	@Test
	public void saveFunction() {
		// TODO: JUnit - Populate test inputs for operation: saveFunction 
		Function function = new cn.edu.scau.cmi.hombio.domain.Function();
		service.saveFunction(function);
	}

	/**
	 * Operation Unit Test
	* Delete an existing Function entity
	* 
	 */
	@Test
	public void deleteFunction() {
		// TODO: JUnit - Populate test inputs for operation: deleteFunction 
		Function function_1 = new cn.edu.scau.cmi.hombio.domain.Function();
		service.deleteFunction(function_1);
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findFunctionByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findFunctionByPrimaryKey 
		Integer id_1 = 0;
		Function response = null;
		response = service.findFunctionByPrimaryKey(id_1);
		// TODO: JUnit - Add assertions to test outputs of operation: findFunctionByPrimaryKey
	}

	/**
	 * Operation Unit Test
	* Delete an existing RoleAuthority entity
	* 
	 */
	@Test
	public void deleteFunctionRoleAuthorities() {
		// TODO: JUnit - Populate test inputs for operation: deleteFunctionRoleAuthorities 
		Integer function_id = 0;
		Integer related_roleauthorities_id = 0;
		Function response = null;
		response = service.deleteFunctionRoleAuthorities(function_id, related_roleauthorities_id);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteFunctionRoleAuthorities
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
